package monitTree;

import com.common.ColonyTool;
import com.common.DeleteTool;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import db_tool.DBConnection;
import db_tool.LogTool;
import db_tool.TimeFormat;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import tree_util.Account;
import tree_util.UpLoadPicture;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class QueryMonit extends ActionSupport {
    private String monitID;

    //树节点分页
    private int pageSize = 18;
    private int pageNumber = 1;

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    private Account account = (Account) ActionContext.getContext().getSession().get("account");

    //获取所有的监测点
    public String MonitSite() throws IOException {
        ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        PrintWriter writer = ServletActionContext.getResponse().getWriter();
        //获取session中保存的用户信息
        //account = (Account) ActionContext.getContext().getSession().get("account");

        String sql = "", sql1 = "";
        DBConnection dbConnection = DBConnection.getInstance();
        Statement statement = null;
        ResultSet rs = null;
        try {
            statement = dbConnection.getStatement();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        if (account.getRoleName().equals("student")) {
//			  sql = "SELECT InverstigationID FROM MonitoringSite where user_id='" + account.getID() + "'";
            sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite where  user_id='" + account.getID() + "'order by InverstigationID ) tb) and user_id='" + account.getID() + "'";
        } else if (account.getRoleName().equals("mentor"))
//			  sql = "SELECT InverstigationID FROM MonitoringSite where user_id IN ( SELECT id FROM Account WHERE superiorName ='"+account.getUsername()+"') OR user_id = '"+account.getID() + "'";
        {
            sql1 = "select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite where  user_id IN ( SELECT id FROM Account WHERE superiorName ='" + account.getUsername() + "') OR user_id = '" + account.getID() + "'order by InverstigationID ) tb";
            try {
                rs = statement.executeQuery(sql1);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String id = "";
            try {
                while (rs.next()) {
                    id = rs.getString(1);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > '" + id + "' and user_id IN ( SELECT id FROM Account WHERE superiorName ='" + account.getUsername() + "') OR user_id = '" + account.getID() + "'";
        }
//			sql = "select top "+pageSize+"InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top ("+pageSize+" * ("+pageNumber+"-1)) InverstigationID from MonitoringSite where  user_id IN ( SELECT id FROM Account WHERE superiorName ='"+account.getUsername()+"') OR user_id = '"+account.getID() + "'order by InverstigationID ) tb) and user_id IN ( SELECT id FROM Account WHERE superiorName ='"+account.getUsername()+"') OR user_id = '"+account.getID() + "'";
        else if (account.getRoleName().equals("privilege")) {
//		  sql = "SELECT InverstigationID FROM MonitoringSite";
            //加上用户权限--select top 10 InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top (10 * (2-1)) InverstigationID from MonitoringSite order by InverstigationID ) tb) and user_id='8'
            sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite order by InverstigationID ) tb)";
        } else {
            writer.write("NO Right!");
            return null;
        }
        String result = "";


        try {
            rs = statement.executeQuery(sql);
            while (rs.next()) {
                result += rs.getString(1) + ",";
            }
            if (result.length() == 0) {
                System.out.println("hahaha");
                writer.write("error");
            } else {
                result = result.substring(0, result.length() - 1);
                writer.write(result);
            }

            System.out.println("monitSite ID result:" + result);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            writer.write("error");
        } finally {
            try {
                dbConnection.close(rs, statement);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }

    //获取监测点总数
    public String GetAllMonit() throws IOException {
        ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        PrintWriter writer = ServletActionContext.getResponse().getWriter();

        String result = "";
        String sql = null;
        int count = 0;

        DBConnection db_connection = DBConnection.getInstance();
        Statement statement = null;
        ResultSet rs = null;

        try {
            statement = db_connection.getStatement();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            if (account.getRoleName().equals("student")) {
                sql = "SELECT InverstigationID FROM MonitoringSite where user_id='" + account.getID() + "'";
            } else if (account.getRoleName().equals("mentor"))
                sql = "SELECT InverstigationID FROM MonitoringSite where user_id IN ( SELECT id FROM Account WHERE superiorName ='" + account.getUsername() + "') OR user_id = '" + account.getID() + "'";
            else
                sql = "SELECT InverstigationID FROM MonitoringSite";

            rs = statement.executeQuery(sql);
            while (rs.next()) {
                count++;
            }
            System.out.println(count);
            writer.write(String.valueOf(count));

        } catch (Exception e) {
            writer.write(result += "00");
            e.printStackTrace();
        } finally {
            try {
                db_connection.close(rs, statement);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }

    //获取当前结点的下一级结点
    public String GetNextMonit() throws IOException {
        System.out.println("开始时间：" + TimeFormat.getNowTime());
        ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        PrintWriter writer = ServletActionContext.getResponse().getWriter();

        String result = "";
        String sql = null, sql1 = null;
        String mID = monitID.substring(0, 3);

        System.out.println("monitID:" + monitID);
        System.out.println("monitName:" + mID);
        System.out.println("页号:" + pageNumber);

        DBConnection db_connection = DBConnection.getInstance();
        Statement statement = null;
        ResultSet rs = null;

        try {
            statement = db_connection.getStatement();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            if (monitID.equals("jjhh")) {
                //搜索监测点
                ///	sql = "select InverstigationID from MonitoringSite";
                if (account.getRoleName().equals("student")) {
//					  sql = "SELECT InverstigationID FROM MonitoringSite where user_id='" + account.getID() + "'";
                    sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite where  user_id='" + account.getID() + "'order by InverstigationID ) tb) and user_id='" + account.getID() + "'";
                } else if (account.getRoleName().equals("mentor"))
//					  sql = "SELECT InverstigationID FROM MonitoringSite where user_id IN ( SELECT id FROM Account WHERE superiorName ='"+account.getUsername()+"') OR user_id = '"+account.getID() + "'";
                {
                    sql1 = "select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite where  user_id IN ( SELECT id FROM Account WHERE superiorName ='" + account.getUsername() + "') OR user_id = '" + account.getID() + "'order by InverstigationID ) tb";
                    rs = statement.executeQuery(sql1);
                    String id = "";
                    while (rs.next()) {
                        id = rs.getString(1);
                    }
                    sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > '" + id + "' and user_id IN ( SELECT id FROM Account WHERE superiorName ='" + account.getUsername() + "') OR user_id = '" + account.getID() + "'";
                } else
//					  sql =  "SELECT InverstigationID FROM MonitoringSite";
                    sql = "select top " + pageSize + "InverstigationID from MonitoringSite where InverstigationID > ( select isnull(max(InverstigationID),0) from (select top (" + pageSize + " * (" + pageNumber + "-1)) InverstigationID from MonitoringSite order by InverstigationID ) tb)";
            } else if (mID.equals("MON")) {
                //搜索断面
                sql = "select ID FROM FractureSurface where ID_MonitoringSite = '" + monitID + "'";

            } else if (mID.equals("SEC")) {
                //搜索测线
                sql = "select ID FROM MeasuringLine where ID_FractureSurface = '" + monitID + "'";

            } else if (mID.equals("LIN")) {
                //搜索测点
                sql = "select ID from MeasuringPoint where ID_MeasuringLine='" + monitID + "'";

            } else if (mID.equals("PNT")) {
                //搜索采样水层
                sql = "select  Layer , ID from WaterLayer where ID_MeasuringPoint='" + monitID + "'";

            } else if (mID.equals("WLE")) {

                String sql2 = "select SampleID from Catches where ID_WaterLayer='" + monitID + "'";
                String sql3 = "select ID from WaterQuality_SurStatMonData where WaterLayer_id='" + monitID + "'";

                Statement statement2 = db_connection.getStatement();
                ResultSet resultSet = statement2.executeQuery(sql2);
                while (resultSet.next()) {
                    result += resultSet.getString(1) + ",";
                }

                Statement statement3 = db_connection.getStatement();
                ResultSet resultSet3 = statement3.executeQuery(sql3);
                while (resultSet3.next()) {
                    result += "WDD" + resultSet3.getInt(1) + ",";
                }

                resultSet.close();
                statement2.close();
                resultSet3.close();
                statement3.close();

                //搜索网具
                sql = "select ID_CatchTools from WaterLayer_CatchTools where ID_WaterLayer='" + monitID + "'";
            } else if (mID.equals("CTH")) {
                //搜索鱼样本
                String sql2 = "select SampleID from Fishes where ID_Catches='" + monitID + "'";
                String sql3 = "select ID from Colony_ResearData where FishClassInfom_ID='" + monitID + "'";

                Statement statement2 = db_connection.getStatement();
                ResultSet resultSet = statement2.executeQuery(sql2);
                while (resultSet.next()) {
                    result += resultSet.getString(1) + ",";
                }

                System.out.println(sql3);
                Statement statement3 = db_connection.getStatement();
                ResultSet resultSet3 = statement3.executeQuery(sql3);
                while (resultSet3.next()) {
                    result += "CRD" + resultSet3.getInt(1) + ",";
                }

                resultSet.close();
                statement2.close();
                resultSet3.close();
                statement3.close();
                //搜索卵样本
                sql = "select SampleID from FishEggs where ID_Catches='" + monitID + "'";
            } else if (mID.equals("FSS")) {
                String sql2 = "select ID from FishResidEnvirPollu_Analysis where FishSample_ID='" + monitID + "'";

                Statement statement2 = db_connection.getStatement();
                ResultSet resultSet = statement2.executeQuery(sql2);
                while (resultSet.next()) {
                    result += "FEP" + resultSet.getInt(1) + ",";
                }

                sql = "select ID from MolecuMaker_Resear where Sample_MeasureNO='" + monitID + "'";
                resultSet.close();
                statement2.close();
            } else if (mID.equals("FSE")) {
                sql = "select ID from MolecuMaker_Resear where Sample_MeasureNO='" + monitID + "'";
            } else if (mID.equals("MMR")) {
                String sql2 = "select ID from Prim where Sample_MeasureNO=" + monitID.substring(3);

                Statement statement2 = db_connection.getStatement();
                ResultSet resultSet = statement2.executeQuery(sql2);
                while (resultSet.next()) {
                    result += "PRI" + resultSet.getInt(1) + ",";
                }

                sql = "select ID from Sample_Info where Sample_MeasureNO=" + monitID.substring(3);
            }

            System.out.println(sql + " this is my sql");
            rs = statement.executeQuery(sql);

            if (mID.equals("FSS") || mID.equals("FSE")) {
                while (rs.next()) {
                    result += "MMR" + rs.getInt(1) + ",";
                }
            } else if (mID.equals("MMR")) {
                while (rs.next()) {
                    result += "SIF" + rs.getInt(1) + ",";
                }
            } else if (mID.equals("PNT")) {
                while (rs.next()) {
                    for (int j = 1; j <= rs.getMetaData().getColumnCount(); j++) {
                        System.out.print(" 33 " + rs.getString(j));
                        if (j == 1)
                            result += rs.getString(j) + ":";
                        else
                            result += rs.getString(j);
                    }
                    result += ",";
                }
            } else {
                while (rs.next()) {
                    result += rs.getString(1) + ",";
                }
            }

            if (result != "" && !result.equals("01") && !result.equals("00")) {
                result = result.substring(0, result.length() - 1);
            }

            writer.write(result);

        } catch (Exception e) {
            System.out.println(result);
            writer.write(result += "00");
            e.printStackTrace();
        } finally {
            try {
                db_connection.close(rs, statement);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }

    //删除选的结点
    public String DeleteSelectMonit() throws IOException {
        ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        System.out.println(monitID + "                                 111111111111111");
        UpLoadPicture.DeleteAll(monitID);
        System.out.println(monitID + "                                 22222222222222");

        ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
        DeleteTool tool = (DeleteTool) context.getBean("deleteTool");
        PrintWriter writer = ServletActionContext.getResponse().getWriter();
        //判断ID是否为int类型
        boolean isInt = false;
        //多选删除
        if (monitID.length() > 17) {
            String[] monitIDs = new String[monitID.length() / 17];
            for (int i = 0; i < monitIDs.length; i++) {
                monitIDs[i] = monitID.substring(0, 17);
                monitID = monitID.substring(17);
                System.out.println(monitIDs[i]);
            }
            boolean flag = true;
            for (String monitID1 : monitIDs) {
                if (!deleteOne(tool, monitID1, isInt)) {
                    flag = false;
                }
            }
            if (flag) {
                writer.write("success");
            } else {
                writer.write("error");
            }
            writer.close();
            return null;
        } else { //单节点删除
            if (deleteOne(tool, monitID, isInt)) {
                writer.write("success");
            } else {
                writer.write("error");
            }
            writer.close();
            return null;
        }
    }

    //获取每一个节点详细信息
    public String ShowMessage() throws IOException {
        ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        PrintWriter writer = ServletActionContext.getResponse().getWriter();

        String mID = monitID.substring(0, 3);
        String result = "";
        String sql = "";

        DBConnection db_connection = DBConnection.getInstance();
        Statement statement = null;
        ResultSet rs = null;
        try {
            statement = db_connection.getStatement();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            if (mID.equals("MON")) {
                //监测点
                sql += "select * from MonitoringSite where InverstigationID='" + monitID + "'";

            } else if (mID.equals("SEC")) {
                //断面
                sql += "select * from FractureSurface where ID='" + monitID + "'";

            } else if (mID.equals("LIN")) {
                //测线
                sql += "select * from MeasuringLine where ID='" + monitID + "'";

            } else if (mID.equals("PNT")) {
                //测点
                sql += "select * from MeasuringPoint where ID='" + monitID + "'";

            } else if (mID.equals("WLE")) {
                System.out.println("采样水层查询进入");
                //采样水层
                sql += "select * from WaterLayer where ID='" + monitID + "'";

            } else if (mID.equals("NET")) {
                //网具
                sql += "select * from CatchTools where SampleID='" + monitID + "'";

            } else if (mID.equals("WDD")) {
                //水质监测数据
                sql += "select * from WaterQuality_SurStatMonData where ID=" + monitID.substring(3);

            } else if (mID.equals("CTH")) {
                //渔获物
                sql += "select * from Catches where SampleID='" + monitID + "'";

            } else if (mID.equals("FSS")) {
                //鱼样本
                sql += "select * from Fishes where SampleID='" + monitID + "'";

            } else if (mID.equals("FEP")) {
                //鱼体环境污染
                sql += "select * from FishResidEnvirPollu_Analysis where ID=" + monitID.substring(3);
            } else if (mID.equals("FSE")) {
                //卵样本
                sql += "select * from FishEggs where SampleID='" + monitID + "'";
            } else if (mID.equals("MMR")) {
                //分子样本基础信息
                sql += "select * from MolecuMaker_Resear where ID=" + monitID.substring(3);
            } else if (mID.equals("PRI")) {
                //引物
                sql += "select * from Prim where ID=" + monitID.substring(3);
            } else if (mID.equals("SIF")) {
                //单样本信息
                sql += "select * from Sample_Info where ID=" + monitID.substring(3);
            } else if (mID.equals("CRD")) {
                //单群体计算数据
                sql += "select * from Colony_ResearData where ID=" + monitID.substring(3);
            } else if (mID.equals("PHY")) {
                //浮游动物
                sql += "select * from Phytoplankton where SampleID='" + monitID + "'";

            } else if (mID.equals("ZOO")) {
                //浮游植物
                sql += "select * from Zooplankton where SampleID='" + monitID + "'";

            } else if (mID.equals("BEN")) {
                //底栖生物
                sql += "select * from Benthos where SampleID='" + monitID + "'";

            } else if (mID.equals("PPH")) {
                //浮游生物优势物种
                sql += "select * from DominantPhytoplanktonSpecies where SampleID='" + monitID + "'";

            } else if (mID.equals("PZO")) {
                //浮游植物优势物种
                sql += "select * from DominantZooplanktonSpecies where SampleID='" + monitID + "'";

            } else if (mID.equals("PBE")) {
                //底栖生物优势物种
                sql += "select * from DominantBenthosSpecies where SampleID='" + monitID + "'";

            } else if (mID.equals("SED")) {
                //沉淀物
                sql += "select * from Sediment where SampleID='" + monitID + "'";
            }

            rs = statement.executeQuery(sql);

            if (mID.equals("WDD") || mID.equals("FEP") || mID.equals("MMR") || mID.equals("PRI")) {
                while (rs.next()) {
                    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
                        if (i < 3) {
                            result += rs.getInt(i) + ",";
                        } else {
                            result += rs.getString(i) + ",";
                        }
                }
            } else if (mID.equals("SIF")) {
                while (rs.next()) {
                    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
                        if (i < 2) {
                            result += rs.getInt(i) + ",";
                        } else {
                            result += rs.getString(i) + ",";
                        }
                }
                System.out.println(result);
            } else if (mID.equals("CRD")) {
                while (rs.next()) {
                    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
                        if (i == 1 || i == 2 || i == 5 || i == 6 || i == 9) {
                            result += rs.getInt(i) + ",";
                        } else {
                            result += rs.getString(i) + ",";
                        }
                }
            } else {
                while (rs.next()) {
                    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
                        result += rs.getString(i) + ",";
                }
            }

            result = result.substring(0, result.length() - 1);
            if (mID.equals("PNT")) {
                result += "_";
                String string1;
                String sql2 = "select * from WaterLayer where ID_MeasuringPoint='" + monitID + "'";
                //这一步获取测点下的采样水层的全部信息。
                Statement st = db_connection.getStatement();
                ResultSet da = st.executeQuery(sql2);
                while (da.next()) {
                    for (int j = 1; j <= da.getMetaData().getColumnCount(); j++) {
                        string1 = da.getString(j);
                        result += string1 + ",";
                    }
                    result += "_";
                }
                result = result.substring(0, result.length() - 2);
                System.out.println(result);
            }
            writer.write(result);

        } catch (Exception e) {
            writer.write("error");
            System.out.println(e);
        } finally {
            try {
                db_connection.close(rs, statement);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;
    }

    public String getMonitID() {
        return monitID;
    }

    public void setMonitID(String monitID) {
        this.monitID = monitID;
    }

    private boolean deleteOne(DeleteTool tool, String monitID, boolean isInt) {
        String mID = monitID.substring(0, 3);
        String delete = null;            //删除操作的SQL语句

        if (mID.equals("MON")) {
            //删除监测点
            delete = "delete from MonitoringSite where InverstigationID=?";

        } else if (mID.equals("SEC")) {
            //删除断面
            delete = "delete from FractureSurface where ID=?";

        } else if (mID.equals("LIN")) {
            //删除测线
            delete = "delete from MeasuringLine where ID=?";

        } else if (mID.equals("PNT")) {
            //删除测点
            delete = "delete from MeasuringPoint where ID=?";

        } else if (mID.equals("WLE")) {
            //删除采样水层
            delete = "delete from WaterLayer where ID=?";

        } else if (mID.equals("NET")) {
            //删除网具
            delete = "delete from CatchTools where SampleID=?";

        } else if (mID.equals("WDD")) {
            //删除水质监测数据
            delete = "delete from WaterQuality_SurStatMonData where ID=?";
            isInt = true;

        } else if (mID.equals("CTH")) {
            //删除渔获物
            delete = "delete from Catches where SampleID=?";

        } else if (mID.equals("FSS")) {
            //删除鱼样本
            delete = "delete from Fishes where SampleID=?";

        } else if (mID.equals("FEP")) {
            //删除鱼体环境污染
            delete = "delete from FishResidEnvirPollu_Analysis where ID=?";
            isInt = true;

        } else if (mID.equals("MMR")) {
            //删除分子样本基础信息
            delete = "delete from MolecuMaker_Resear where ID=?";
            isInt = true;

        } else if (mID.equals("PRI")) {
            //删除引物
            delete = "delete from Prim where ID=?";
            isInt = true;

        }else if (mID.equals("SIF")) {
            //删除单样本信息
            delete = "delete from Sample_Info where ID=?";
            isInt = true;

        } else if (mID.equals("FSE")) {
            //删除卵样本
            delete = "delete from FishEggs where SampleID=?";

        } else if (mID.equals("CRD")) {
            //删除单群体计算
            delete = "delete from Colony_ResearData where ID=?";
            isInt = true;

        } else if (mID.equals("PHY")) {
            //删除浮游植物
            delete = "delete from Phytoplankton where SampleID=?";

        } else if (mID.equals("ZOO")) {
            //删除浮游动物
            delete = "delete from Zooplankton where SampleID=?";

        } else if (mID.equals("BEN")) {
            //删除底栖动物
            delete = "delete from Benthos where SampleID=?";

        } else if (mID.equals("PPH")) {
            //删除浮游植物优势种
            delete = "delete from DominantPhytoplanktonSpecies where SampleID=?";

        } else if (mID.equals("PZO")) {
            //删除浮游动物优势种
            delete = "delete from DominantZooplanktonSpecies where SampleID=?";

        } else if (mID.equals("PBE")) {
            //删除底栖动物优势种
            delete = "delete from DominantBenthosSpecies where SampleID=?";

        } else if (mID.equals("SED")) {
            //删除沉淀物
            delete = "delete from Sediment where SampleID=?";
        }

        if (isInt) {
            return tool.delete(delete, Integer.valueOf(monitID.substring(3))) > 0;
        } else {
            return tool.delete(delete, monitID) > 0;
        }
    }

}
